#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QMessageBox>
#include<QFileDialog>
#include<QColorDialog>
#include<QInputDialog>
#include<QFontDialog>
#include<QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    QMessageBox* megbox=new QMessageBox(this);
    megbox->setWindowTitle("对话框标题");
    megbox->setText("严重错误！！！");
    megbox->setIcon(QMessageBox::Question);
    megbox->setStandardButtons(QMessageBox::Ok|QMessageBox::Cancel);
    int result=megbox->exec();
    if (result == QMessageBox::Ok) {
        qDebug() << "Ok";
    } else if (result == QMessageBox::Cancel) {
        qDebug() << "Cancel";
    }
}

void MainWindow::on_pushButton_8_clicked()
{
    int result = QMessageBox::question(this, "对话框标题", "不保存？？？", QMessageBox::Ok | QMessageBox::Cancel);
       if (result == QMessageBox::Ok) {
           qDebug() << "Ok";
       } else if (result == QMessageBox::Cancel) {
           qDebug() << "Cancel";
       }
}

void MainWindow::on_pushButton_6_clicked()
{
    int result = QMessageBox::information(this, "对话框标题", "我是帅哥", QMessageBox::Ok | QMessageBox::Cancel);
       if (result == QMessageBox::Ok) {
           qDebug() << "Ok";
       } else if (result == QMessageBox::Cancel) {
           qDebug() << "Cancel";
       }
}

void MainWindow::on_pushButton_7_clicked()
{
    int result = QMessageBox::warning(this, "对话框标题", "我是帅哥吗！", QMessageBox::Ok | QMessageBox::Cancel);
       if (result == QMessageBox::Ok) {
           qDebug() << "Ok";
       } else if (result == QMessageBox::Cancel) {
           qDebug() << "Cancel";
       }
}

void MainWindow::on_pushButton_5_clicked()
{
    QColor color = QColorDialog::getColor(QColor(0, 255, 0), this, "选择颜色");
        qDebug() << color;
}

void MainWindow::on_pushButton_2_clicked()
{
    QString str=QFileDialog::getOpenFileName(this,"打开的文件");
    qDebug()<<str;
}

void MainWindow::on_pushButton_9_clicked()
{
    QString str=QFileDialog::getSaveFileName(this,"保存的文件");
    qDebug()<<str;
}

void MainWindow::on_pushButton_3_clicked()
{
       bool ok = false;
       QFont font = QFontDialog::getFont(&ok);
       qDebug() << "ok = " << ok;
       // qDebug() << font;
       qDebug() << font.family();
       qDebug() << font.pointSize();
       qDebug() << font.bold();
       qDebug() << font.italic();

       ui->pushButton->setFont(font);
}

void MainWindow::on_pushButton_4_clicked()
{
    int tmp=QInputDialog::getInt(this,"请输入整数","整数");
    qDebug()<<tmp;
}
